unit Con_Maquina;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids,dbtables,db;

type
  TFrmConMaquina = class(TFrmConsulta)
    Label2: TLabel;
    Edt_Descricao: TEdit;
    DbGrid: TDBGrid;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
    procedure Edt_DescricaoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    cod_maquina : string;
    procedure FazConsulta;
  end;

var
  FrmConMaquina: TFrmConMaquina;

implementation

uses clsMaquina,dm;
var
  Maquina: TMaquina;
  tq     : TQuery;
  tds    : TDataSource;

{$R *.DFM}

{ TFrmConMaquina }

procedure TFrmConMaquina.FazConsulta;
begin
  if Edt_Descricao.Text = '' then
    Edt_Descricao.Text := ' ';
  Maquina.Consultar(tq,Edt_Descricao.Text);
  tq.Open;
  DbGrid.DataSource := tds;
  DbGrid.Refresh;
end;

procedure TFrmConMaquina.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Maquina.free;
end;

procedure TFrmConMaquina.FormCreate(Sender: TObject);
begin
  inherited;
  Maquina := TMaquina.create;
end;

procedure TFrmConMaquina.BtnFecharClick(Sender: TObject);
begin
  inherited;
  cod_maquina := tq.fieldbyname('cod_maquina').AsString;
  tq.close;
  tq.free;
  tds.free;
end;

procedure TFrmConMaquina.Edt_DescricaoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then
  begin
    FazConsulta;
    Edt_Descricao.SetFocus;
  end;
end;

procedure TFrmConMaquina.FormActivate(Sender: TObject);
begin
  inherited;
  tq         := TQuery.create(DmInt);
  tq.DatabaseName := DmInt.Db.DatabaseName;
  tds        := TDataSource.Create(DmInt);
  tq.Active  := false;
  tds.DataSet:= tq;
  DbGrid.DataSource := tds;
  FazConsulta;
  Edt_Descricao.SetFocus;
end;

end.
